import random

ran = random.random()
print(ran)
r = random.randrange(1, 10, 2)  # randrange(start,stop,step) 1,3,5,7,9
print(r)
r = random.randint(1, 10)  # 会产生10的元素
print(r)
list1 = ['高嘉银', '廖立晴', '詹姆斯', '科比']
r = random.choice(list1)
print(r)

list2 = [1, 2, 3, 4, 5]
random.shuffle(list2)  # 会把列表的元素打乱排序，洗牌的作用
print(list2)


# 产生验证码函数
def valid_code():
    code = ''
    for i in range(4):
        ran1 = str(random.randint(0, 9))
        ran2 = chr(random.randint(65, 90))
        ran3 = chr(random.randint(97, 122))
        r1 = random.choice([ran1, ran2, ran3])
        code += r1
    return code


print(valid_code())
# unicode码的转换
print(chr(65))  # 把unicode码转为字母
print(ord('A'))  # 把字母转为unicode数字
print(ord('上'))
